﻿CREATE PROCEDURE [dbo].[UpdateProjectMembers]
@ID UNIQUEIDENTIFIER, @projectID INT, @userID INT, @startDate DATETIME, @endDate DATETIME, @hourlyRate MONEY, @isRemoved BIT
AS
BEGIN
    SET NOCOUNT ON;

IF ( @isRemoved = 1)
		DELETE FROM [dbo].[ProjectMembers]
		WHERE [ID] = @ID
ELSE
	BEGIN
		UPDATE [dbo].[ProjectMembers]
			SET [StartDate] = @startDate
			,[EndDate] = @endDate
			,[HourlyRate] = @hourlyRate
			WHERE [ID] = @ID
 
		IF (@@ROWCOUNT = 0 )
		BEGIN
			INSERT INTO [dbo].[ProjectMembers]
			(	ID, ProjectID, UserID, StartDate, EndDate, HourlyRate)	
			VALUES 
			(
				@ID ,@projectID, @userID, @startDate, @endDate, @hourlyRate
			)
		END
	END
END;

